package main

import (
	"encoding/json"
	"log"
	"net/http"
	"time"
)

type Project struct {
	ID          int       `json:"id"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	ImageURL    string    `json:"imageUrl"`
	Date        time.Time `json:"date"`
	Category    string    `json:"category"`
}

type About struct {
	Name        string   `json:"name"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Skills      []string `json:"skills"`
	SocialLinks []string `json:"socialLinks"`
}

var projects = []Project{
	{
		ID:          1,
		Title:       "创意设计项目",
		Description: "一个充满创意的设计项目，展示了独特的视觉风格",
		ImageURL:    "http://xvwen.cn:8080/api/public/dl/rd7dU-Am/desgin.png",
		Date:        time.Now(),
		Category:    "设计",
	},
	{
		ID:          2,
		Title:       "Web开发项目",
		Description: "一个现代化的Web应用开发项目",
		ImageURL:    "http://xvwen.cn:8080/api/public/dl/rd7dU-Am/web_pic.png",
		Date:        time.Now().AddDate(0, -1, 0),
		Category:    "开发",
	},
}

var about = About{
	Name:        "创意工作室",
	Title:       "创意设计师 & 开发者",
	Description: "我们是一个充满激情的创意团队，专注于提供独特的设计和开发解决方案。",
	Skills:      []string{"UI/UX设计", "Web开发", "品牌设计", "平面设计"},
	SocialLinks: []string{"https://github.com", "https://linkedin.com", "https://twitter.com"},
}

func getProjects(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	w.Header().Set("Access-Control-Allow-Origin", "*")
	json.NewEncoder(w).Encode(projects)
}

func getAbout(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	w.Header().Set("Access-Control-Allow-Origin", "*")
	json.NewEncoder(w).Encode(about)
}

func main() {
	http.HandleFunc("/api/projects", getProjects)
	http.HandleFunc("/api/about", getAbout)
	
	// 提供静态文件服务
	fs := http.FileServer(http.Dir("./static"))
	http.Handle("/", fs)

	log.Println("Server starting on :8080...")
	log.Fatal(http.ListenAndServe(":8080", nil))
} 